Skip to content

build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218

Merged
natecraddock merged 1 commit into
natecraddock:mainfrom
Rawan10101:main
Jun 13, 2026
Merged

build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218
natecraddock merged 1 commit into
natecraddock:mainfrom
Rawan10101:main

Conversation

@Rawan10101

Copy link
Copy Markdown
Contributor

When building Lua for wasm32 with Emscripten, WebAssembly does not natively support traditional setjmp/longjmp semantics. Emscripten implements support by applying compiler and linker transformations that rewrite and instrument setjmp/longjmp usage. But when Lua is compiled by Zig as a separate static library outside Emscripten's normal compilation pipeline. Without -flto, Zig compiles Lua's source files into object code that Emscripten cannot fully analyze or rewrite during the final link step which prevents the required setjmp/longjmp transformations from being applied correctly.

Adding -flto for the wasm32 build causes Zig to preserve LLVM IR in the generated artifacts. When emcc performs the final link, it can see inside the Lua code and apply its setjmp/longjmp instrumentation passes across the entire program.

Note: This issue was discovered while building Neovim for WebAssembly as part of the active Neovim wasm project: neovim/neovim#39987

@natecraddock

Copy link
Copy Markdown
Owner

Makes sense to me! Thanks for fixing this

@natecraddock natecraddock merged commit 2f0f668 into natecraddock:main Jun 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants